<?php

namespace Xehang\AliyunOss;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use OSS\OssClient;

class AliyunOssServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('aliyun-oss', function ($app, $config) {
            $accessId  = $config['access_id'];
            $accessSecret = $config['access_secret'];
            $endpoint  = $config['endpoint'];
            $bucket    = $config['bucket'];
            $domain    = $config['domain'];
            $ssl       = $config['ssl'] ? true : false;

            $client  = new OssClient($accessId, $accessSecret, $endpoint);
            $adapter = new AliyunOssAdapter($client, $bucket, $endpoint, $domain, $ssl);

            return new Filesystem($adapter);
        });
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
